package com.zhuiyun.project.api.learnPlan.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageHelper;
import com.zhuiyun.project.api.learnPlan.entity.Zong;
import com.zhuiyun.project.api.learnPlan.mapper.ZongMapper;
import com.zhuiyun.project.api.learnPlan.model.LearnPlanModel;
import com.zhuiyun.project.api.learnPlan.service.ZongService;
import com.zhuiyun.project.api.poetryAuthor.entity.PoetryAuthor;
import com.zhuiyun.project.api.poetryAuthor.model.PoetryAuthorModel;
import com.zhuiyun.project.common.errorCode.EmErrorCode;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.ObjectUtils;
import com.zhuiyun.project.utils.pageUtil.MybatisPageHelper;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import com.zhuiyun.project.utils.pageUtil.PageResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description TODO
 * @Author zf
 * @Date 2024/3/21 9:11
 */
@Service
public class ZongServiceImpl implements ZongService {

    @Resource
    private ZongMapper zongMapper;

    /**
     * @Description TODO 查询学习计划
     * @Author zf
     * @param learnPlanModel
     * @param pageRequest
     * @Date 2024/3/21 9:11
     */
    @Override
    public CommonResult ListLearnPlan(LearnPlanModel learnPlanModel, PageRequest pageRequest) {
        PageHelper.startPage(pageRequest);
        Zong z= BeanUtil.toBean(learnPlanModel, Zong.class);
        List<Zong> zong = zongMapper.selectLearPlan(z);
        PageResult pageResult= MybatisPageHelper.getPageResult(zong);
        if(ObjectUtils.isNotEmpty(pageResult)){
            return CommonResult.ok(pageResult);
        }else {
            return CommonResult.error(EmErrorCode.ID_NOT_OBJECT);
        }
    }
}
